﻿using System;
using System.Threading;
using OmegaBot;

namespace drone_cc
{
    public class droneWarlockCombat : CombatClass
    {
        //TODO:

        #region properties / class setup
        //combat abilities
        SpellKeyDefinition stealth;



        public IniManager Ini;

        public override string CombatClassName { get { return "drone-cc warlock"; } }

        public override void CreateSetup()
        {
            Ini = new IniManager("drone-cc.ini");
            Ini.SetComment("drone-cc.ini\r\n\r\nconfiguration for drone-cc");

            //combat spells
           

            Ini.Set("warlock", "usemount", "false");
            Ini.Set("warlock", "skiplootcheck", "false");
            Ini.Set("warlock", "mountdistance", "30");

            Ini.Set("warlock", "combineitems", "false");
            Ini.Set("warlock", "openclams", "false");
            Ini.Set("warlock", "enablepvp", "false");
           
            Ini.Load();
            Ini.Save();
        }

        // Make our special setup window and return it so it can be shown:
        protected override ClassSetupPanel CreateSetupPanel()
        {
            return new droneWarlockSetup(this);
        }

        protected override void SetupKeys()
        {
            Log.WriteLine("Drone is setting up spell keys");
            
            //combat abilities
            stealth = SpellKeys.CreateFromSpell("stealth", 1784);


            //mounts
            DroneCombatClassUtilties.setupMountSpellKeys(SpellKeys);

            // Set up normal options for these spells:
            stealth.SetDefaultOptions(CastOptions.ChainCast);


        }
        #endregion

        #region Resting / Healing / Buffs



        public override bool CanDrink
        {
            get
            {
                return true;
            }
        }

        public override bool DoLightHeal()
        {
            return false;

        }

        public override bool DoBigHeal()
        {
            return false;

        }

        public override void Buff()
        {
            //Item Combine
            if (DroneCombatClassUtilties.needCombine() &&
                Ini.GetBoolean("warlock", "combineitems", false))
            {
                DroneCombatClassUtilties.combineItems(this.Input);
            }

            //open clams
            if (DroneCombatClassUtilties.needOpenClams() &&
                Ini.GetBoolean("warlock", "openclams", false))
            {
                DroneCombatClassUtilties.combineItems(this.Input);
            }

            //mount section
            if (!Me.isMounted() &&
                Ini.GetBoolean("warlock", "usemount", false))
            {
                if (Me.mustMount(Ini, "warlock"))
                {
                    Me.mountUp(this.Input);
                }
            }

        }


        #endregion

        #region Combat
        protected override CombatResult Combat(GameUnit Target)
        {
           

            if (Me.isMounted())
            {
                Me.dismount();
                Input.ReleaseAllKeys();
            }

            if (!Target.IsMob && !Ini.GetBoolean("warlock", "enablepvp", false))
            {
                Log.WriteLine("Attempted to Target player on accident!");
                return CombatResult.Retry;
            }


            // Main loop!
            while (true)
            {
                GameUnit extra = GameUnit.GetNearestAttacker(Target.GUID);
                CombatResult result = CheckCommonCombatResult(Target, false);

                Thread.Sleep(107);
                if (result != CombatResult.Unknown)
                {
                    return result;
                }

                // Adjust Ourselves
                if (Target.Distance > 5.0)
                {
                    Target.GoTo();
                    Input.ReleaseAllKeys();
                    continue;
                }
                else
                {
                    Target.Face();
                    Target.AdjustForMelee(true);
                    Input.ReleaseAllKeys();
                }
                // End Adjust

            }//End While
        }//End Combat
        #endregion
    }
}